package com.neusoft.utils.jsp;

import java.lang.reflect.InvocationTargetException;

import javax.servlet.jsp.PageContext;

import jodd.util.ReflectUtil;

import com.neusoft.utils.springmvc.SpringContextUtils;
import com.neusoft.utils.string.StringUtil;

public class WorkItemTag extends ValueTag{
	
	
	@Override
	public void work(PageContext pageContext) {
	    Object bean=	pageContext.getAttribute(attr);
	    String[] works= work.split("\\.");
		Object workClass =SpringContextUtils.getBean(works[0]);
		Object workResult = null;
		try {
			workResult = ReflectUtil.invoke(workClass, works[1], bean);
		} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		pageContext.setAttribute("work"+StringUtil.captureFirst(attr), workResult);
	}
	/**
	 *  
	 */
	private static final long serialVersionUID = -6238415907859202220L;
	private String attr;
	private String work;
	public String getAttr() {
		return attr;
	}
	public void setAttr(String attr) {
		this.attr = attr;
	}
	public String getWork() {
		return work;
	}
	public void setWork(String work) {
		this.work = work;
	}


}
